package com.fit.dao.project;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;

import com.fit.entities.Project;

public class ProjectDAOImpl implements ProjectDAO{


	
	@Inject
	private Session session;
	
	public boolean save(Project newProject) {
		if (newProject != null) {
			session.save(newProject);
			return true;
		}
		return false;
		
	}

	public boolean delete(Project project) {
		if (project != null) {
			session.delete(project);
			return true;
		}
		return false;
	}

	public boolean update(Project project) {
		if (project != null) {
			session.update(project);
			return true;
		}
		return false;
	}

	public List<Project> findAll() {
		return session.createCriteria(Project.class).list();
		
	}

	public Project findByID(Long id) {
		if (id != null) {
			return (Project) session.get(Project.class, id);
		}
		return null;
	}

	public boolean deleteByID(Long id) {
		Project p = findByID(id);
		if (p != null) {
			delete(p);
			return true;
		}
		return false;
	}
}
